/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DBTables;

import DBManager.*;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.ParameterMetaData;
import java.sql.SQLException;

/**
 *Класс таблицы Project
 * @author Иван
 */
public class TProject extends DataManager {

    public String Id_ObjectiveFK;
    public String Id_CommandFK;
    public String Name;
    public String Discription;
    public String Date_of_inception;
    public String Date_of_end;
    public String Status;

    public TProject(Connection conn, String tableName) throws SQLException {
        super(conn, tableName);

        SelectPrepStatement = connection.prepareStatement("select * from " + TableName);
        InsertPrepStatement = connection.prepareStatement("insert into " + TableName + "(Id_Objective, Id_Command, Name, Discription, Date_of_inception, Date_of_end, Status) values (?,?,?,?,?,?,?) ");
        UpdatePrepStatement = connection.prepareStatement("update " + TableName + " (Id_Objective = ? , Id_Command = ?, Name = ?, Discription = ?,  Date_of_inception = ?, Date_of_end = ?, Status = ?) Where Id_Project = ?");
        DeletePrepStatement = connection.prepareStatement("delete from" + TableName + " Where Id_Project = ?");
    }

    @Override
    public void SetValues(PreparedStatement prepareStatement) throws SQLException {

        ParameterMetaData metaData = prepareStatement.getParameterMetaData();
        int countParameters = metaData.getParameterCount();

        if (countParameters >= 7) // for insert prepared statement
        {
            prepareStatement.setString(1, Id_ObjectiveFK);
            prepareStatement.setString(2, Id_CommandFK);
            prepareStatement.setString(3, Name);
            prepareStatement.setString(4, Discription);
            prepareStatement.setString(5, Date_of_inception);
            prepareStatement.setString(6, Date_of_end);
            prepareStatement.setString(7, Status);
        }

        if ((countParameters == 8))// for update prepared statement
        {
            prepareStatement.setString(8, ID_Table);
        }

        if ((countParameters == 1))// for delete prepared statement
        {
            prepareStatement.setString(1, ID_Table);
        }
    }
}
